require([
  'jquery',
  'pageInit',
  'dataTableFilter',
  'loading',
], function($, vamakerPage, VamDataTable, VamLoader) {
  $(function() {
    var 
      $dataTable = $('#data-table'),
      dataUrl = VAM.getVar('DATA_LIST_URL'),
      dataEidtUrl = VAM.getVar('DATA_EDIT_URL'),
      dataLinkUrl = VAM.getVar('LINK_URL'),
      isAllBrand = VAM.getVar('IS_ALL_BRAND'),
      $reportDataThead = $dataTable.find('thead'),
      $loadingWrap = new VamLoader().loader($('#list-loading-wrap')),
    listTable, tableOptions = {};
    $('.new-operate-btn').on('click', function(evt){
      if (isAllBrand) {
        evt.preventDefault();
        $('#all_tip').removeClass('hidden');
      }
    }) 
    // Table settings.
    tableOptions = {
      'ajax': {
        'url': dataUrl
      },
      'order': [6, 'desc'],
      'columns': [
        {'data': 'id'},
        {'data': 'name'},
        {'data': 'advertiser'},
        {'data': 'status'},
        {'data': 'launchNum'},
        {'data': 'comment'},
        {'data': 'modifiedDate'},
        {'data': 'operate'}
      ],
      'columnDefs': [
        {
          'targets': 0,
          'render': function (data, type, full, meta) {
            var ckbText = '<label><input class="ckb-children" type="checkbox" value="' + data + '"/></label>';
            ckbText = '';
            return '<p title="' + data + '">' + ckbText + data +'</p>';
          }
        },
        {
          'targets': 3,
          'visible': false,       
          'render': function (data, type, full, meta) {
            var result = data;
            return '<p title="' + result + '">' + result +'</p>';
          }
        },
        {
          'targets': [2,5,6],
          'render': function (data, type, full, meta) {
            return '<p title="' + data + '">' + data +'</p>';
          }
        },
        {
          'targets': [1,4],
          'render': function (data, type, full, meta) {
            var result;
            if (full.launchNum === 0) {
              return '<p title="' + data + '">' + data +'</p>';
            };
            result = '<p class="text-primary" title="' + VAM.j('Click to view the campaign corresponding launch') + '"><a href="' + dataLinkUrl + '?label_id=' + full.id + '" target="_blank">' + data + '</a></p>';
            return result;
          }
        },
        {
          'targets': -1,
          'render': function (data, type, full, meta) {
            return '<div class="tab-btn-group">'
                  + '<input type="hidden" class="row-info" value="' + full.id + '"/>'
                  + '<a href="' + dataEidtUrl + '?id=' + full.id + '" class="btn btn-primary btn-xs tab-edit" data-type="edit" title="' + VAM.j('Edit') + '"><i class="fa fa-edit"></i></a>'
                  // + '<a href="#" class="btn btn-info btn-xs tab-report" data-type="report" title="报表"><i class="fa fa-file-text"></i></a>'
                  // + '<button class="btn btn-success btn-xs tab-more" data-type="view" title="查看"><i class="fa fa-eye"></i></button>'
                  + '</div>';
          }
        }
      ],
      'initComplete': function() {
        tableResize = new VamDataTable().columnResize($dataTable);
      },
      'vamSettings': {
        'vamListDateFilter': true,
      }
    };
    $dataTable
    .on('preXhr.dt', function(evt) {
      $loadingWrap.show();
    });
    listTable = new VamDataTable().dataTables($dataTable, tableOptions);
    // After table data list.
    listTable.on('xhr.dt', function(evt) {
      $loadingWrap.fadeOut();
    });
  });
});
